<template>
	<view class="content">
		<uni-nav-bar v-if="!isApp" left-icon="back" title="邀请好友一起早起" shadow="false" @click-left="back()" :fixed="true"></uni-nav-bar>
		<view class="invitation" :style="{'padding-top':isApp ? '0' : '88upx' }">
			<image class="invitation_bg" :style="{'top':isApp ? '0' : '88upx' }" src="/static/invit/bg.jpg" mode=""></image>
			<view class="invitation_main clear">
				<view class="fl">
					<view class="fl_title">
						<text>我在早起打卡活动中</text>
						<text>已坚持</text>
					</view>
					<view class="fl_day">
						<text class="number">{{datas.signUpDays}}</text>
						<text class="day">天</text>
					</view>
					<view class="fl_Cumulative">
						<view class="cumulative">累计获得早起奖励</view>
						<view class="c_number">
							<text class="number">{{datas.allProfit}}</text>
							<text class="coin">{{CODECONFIG.signBaseCode}}</text>
						</view>
					</view>
				</view>
				<view class="fr">
					<view class="fr_title">
						<text>“人应该早起的,早起看灿</text>
						<text>烂辉煌的太阳,因为太阳</text>
						<text>的光明很难持续一整天。</text>
						<text style="text-decoration: none;">--[英]狄更斯”</text>
					</view>
				</view>
			</view>
			<view class="invitation_qrcode clear">
				<view class="code fl">
					<image class="ewm-logo" :src="img" mode=""></image>
					<!-- <view>
            <tki-qrcode ref="qrcode" :val="url" icon="/static/invit/codeIcon.png" :loadMake="true" size="160" :onval="true" />
          </view> -->
				</view>
				<view class="fr">
					<text>扫描左侧二维码</text>
					<text>跟我一起打卡吧</text>
				</view>
			</view>
		</view>
		<HMmessages ref="HMmessages" @complete="HMmessages = $refs.HMmessages" @clickMessage="clickMessage"></HMmessages>
	</view>
</template>

<script>
	import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
	import QR from "@/static/js/wxqrcode.js" // 二维码生成器 
	import service from './service.js';
	import HMmessages from '@/components/HM-messages/HM-messages.vue';
	import {
		mapGetters
	} from 'vuex'
	export default {
		components: {
			uniNavBar,
			HMmessages
		},
		computed: {
			...mapGetters(['CODECONFIG'])
		},
		data() {
			return {
				isApp: uni.getStorageSync('isAppH5'),
				url: '',
				datas: {
					allInvest: 0,
					allProfit: 0,
					signUpDays: 0
				},
				img: '',
			};
		},
		onLoad() {

		},
		onShow() {
			this.getData();
			this.getInviteCode();

		},
		methods: {
			//获取邀请码
			getInviteCode() {
				service.getInviteCode().then(({
					data
				}) => {
					if (data.code == '100200') {
						this.code = data.data;
						this.url = `http://lkex.co/#/pages/register/register?code=${this.code}`;
						this.img = QR.createQrCodeImg(this.url, {
							size: parseInt(300) //二维码大小  
						})
					} else {
						this.errors(data.msg);
					}
				})
			},
			//获取打卡数据
			getData() {
				service.getAllprofit().then(({
					data
				}) => {
					if (data.code == '100200') {
						this.datas = data.data;
					} else {
						this.errors(data.msg);
					}
				})
			},
			//修改手机返回
			back() {
				let length = getCurrentPages();
				if (length.length == 1) {
					uni.switchTab({
						url: '../index/index'
					});
				} else {
					uni.navigateBack();
				}
			},
			//错误提示
			errors(text) {
				this.HMmessages.show(text, {
					textAlign: 'center',
					background: '#74272d',
					fontColor: '#fff'
				});
			}
		}
	};
</script>

<style lang="scss">
	@import './style.scss';
</style>
